package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.Groupon;
import com.cskaoyan.bean.GrouponRules;
import com.cskaoyan.bean.ListData;
import com.cskaoyan.service.AdminGrouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @author 杨杰
 * @version V1.0
 * @Package com.cskaoyan.controller
 * @date 2020/12/10 21:47
 * @Copyright © 暂时还没有
 * @description
 */
@Controller
@RequestMapping("admin/groupon")
public class AdminGrouponController {

    @Autowired
    AdminGrouponService adminGrouponService;

    @RequestMapping("list")
    @ResponseBody
    public BaseRespVo grouponList
            (Integer goodsId,Integer page,Integer limit,String sort,String order){

        ListData<GrouponRules> grouponRules = adminGrouponService.grouponList
                                                   (goodsId, page, limit, sort, order);
        return BaseRespVo.ok(grouponRules);
    }

    @RequestMapping("update")
    @ResponseBody
    public BaseRespVo grouponUpdate(@RequestBody GrouponRules grouponRules){

        adminGrouponService.grouponUpdate(grouponRules);
        return BaseRespVo.ok();
    }

    //还有增删
    @ResponseBody
    @RequestMapping("create")
    public BaseRespVo grouponInsert
    (@RequestBody GrouponRules grouponRules){
        //goodsId: "1006002", discount: "20", discountMember: "3.", expireTime: "2020-12-31 00:00:00"
       GrouponRules grouponRulesNew = adminGrouponService.grouponInsert(grouponRules.getGoodsId(),
               grouponRules.getDiscount(), grouponRules.getDiscountMember(), grouponRules.getExpireTime());
        return BaseRespVo.ok(grouponRulesNew);
    }

    @ResponseBody
    @RequestMapping("delete")
    public BaseRespVo grouponDelete(@RequestBody GrouponRules grouponRules){
        adminGrouponService.grouponDelete(grouponRules);
        return BaseRespVo.ok();
    }

    @ResponseBody
    @RequestMapping("listRecord")
    public BaseRespVo grouponListRecord
            (Integer goodsId,Integer page,Integer limit,String sort,String order){

        ListData<Groupon> grouponListData =
                adminGrouponService.grouponListRecord(goodsId, page, limit, sort, order);
        return BaseRespVo.ok(grouponListData);
    }


}
